/**
 * Copyright &copy; 2013-2015 山东易科德软件有限公司   All rights reserved.
 */
package cn.net.ecode.modules.sys.entity;

import java.util.Date;
import java.util.List;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;

import cn.net.ecode.common.config.Global;
import cn.net.ecode.common.persistence.DataEntity;
import cn.net.ecode.common.persistence.annotation.Id;
import cn.net.ecode.common.utils.excel.annotation.ExcelField;
import cn.net.ecode.common.utils.excel.fieldtype.CompanyType;
import cn.net.ecode.common.utils.excel.fieldtype.OfficeType;
import cn.net.ecode.common.utils.excel.fieldtype.PostListType;
import cn.net.ecode.common.utils.excel.fieldtype.RoleListType;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;

/**
 * 员工管理Entity
 * @author jiaoanjian、ThinkGem
 * @version 2015-4-24
 */
public class Employee extends DataEntity<Employee> {

	private static final long serialVersionUID = 1L;

	private String empCode; 	// 编码
	private String empName; 	// 名称
	private String empNameEn; 	// 英文名
	private String empNo; 		// 工号
	private Office office; 		// 归属机构
	private Company company; 	// 归属公司
	private String sex; 		// 性别
	private Date birthday; 		// 生日
	private String stations; 	// 岗位
	private String dutyCode; 	// 职务
	private String dutyLevel; 	// 职务级别
	private String postTitle; 	// 职称
	private String postTitleLevel; // 职称级别
	private String isForeign; 	// 是否外籍人士
	private String nation; 		// 民族
	private String polityStatus; // 政治面貌
	private String marriStatus; // 婚姻状况
	private String healthStatus; // 健康状况
	private String nativeplace; // 籍贯
	private String residence; 	// 户口性质
	private String idcard; 		// 身份证
	private Long height; 		// 身高CM
	private Long weight; 		// 体重KG，公斤
	private String archiveNo; 	// 档案编号
	private String education; 	// 教育程度
	private String degrees; 	// 学位
	private String school; 		// 毕业学校
	private String subject; 	// 专业学科
	private Date graduationDate; // 毕业时间
	private String language; 	// 语言/外语
	private String languageLevel; // 语言等级
	private String specialty; 	// 特长
	private String interest; 	// 兴趣爱好
	private String mobile; 		// 移动电话
	private String officePhone; // 办公室电话
	private String fax; 		// 传真
	private String email; 		// 电子邮件
	private String qq; 			// QQ
	private String perResidence; // 户籍
	private String addr; 		// 住址
	private String homePhone; 	// 家庭电话
	private String joinWork; 	// 参加工作年月
	private Date joinCorp; 		// 入职时间
	private String psnBank; 	// 银行
	private String psnAccount; 	// 银行账号
	private String feeBank; 	// 费用银行
	private String feeAccount; 	// 费用银行账号
	private String ssno; 		// 社会保障号
	private String accumulationAccount; // 公积金账号
	private String picturePath; // 照片路径
	private String servCorpCode; // 劳务公司编码
	private String servCorpName; // 劳务公司名称
	private String mergeAccountid; // 合并账号
	private Date leaveDate; // 离职日期
//	private String employmentForm; // 用工形式（正式、实习、试用、临时、劳务、挂靠）

	private String isLoginUser; // 是否登录用户
	private User loginInfo; //登录用户信息
	
	private String userCode;
	private String userName;
	private String officeCode;
	private String officeName;
	
	private String officeCode2;
	private String officeName2;
	
	private String memberCode;
	private String memberName;
	private String phone;
	
	// 会员的属性，用户列表显示
	
	

	private String postCode; // 根据职位查询
	
	private boolean isAll;	// 查询条件：是否过滤数据控制权限 true 查询所有，false 过滤

	private List<Post> postList = Lists.newArrayList();

	public Employee() {
		super();
	}

	public Employee(String id) {
		super(id);
	}

	@Id
	@ExcelField(title = "员工编码", align = 2, sort = 10)
	public String getEmpCode() {
		return empCode;
	}

	public void setEmpCode(String empCode) {
		this.empCode = empCode;
	}

	@Length(min = 0, max = 100, message = "名称长度不能超过 100 个字符")
	@ExcelField(title = "员工名称", align = 2, sort = 15)
	public String getEmpName() {
		return empName;
	}

	public void setEmpName(String empName) {
		this.empName = empName;
	}

	@Length(min = 0, max = 100, message = "英文名长度不能超过 100 个字符")
	public String getEmpNameEn() {
		return empNameEn;
	}

	public void setEmpNameEn(String empNameEn) {
		this.empNameEn = empNameEn;
	}

	@Pattern(regexp="[a-zA-Z0-9_]{0,30}", message="工号长度不能超过 30 个字符，并且只能包含字母、数字、下划线")
	public String getEmpNo() {
		return empNo;
	}

	public void setEmpNo(String empNo) {
		this.empNo = empNo;
	}

	@NotNull(message = "归属机构不能为空")
	@ExcelField(title = "归属机构", align = 2, sort = 25, fieldType = OfficeType.class)
	public Office getOffice() {
		if (office == null) {
			office = new Office();
		}
		return office;
	}

	public void setOffice(Office office) {
		this.office = office;
	}

	@NotNull(message = "归属公司不能为空")
	@ExcelField(title = "归属公司", align = 2, sort = 20, fieldType = CompanyType.class)
	public Company getCompany() {
		if (company == null) {
			company = new Company();
		}
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	@Length(min = 0, max = 2, message = "性别长度不能超过 2 个字符")
	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	@JsonFormat(pattern = "yyyy-MM-dd")
	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	@Length(min = 0, max = 300, message = "岗位长度不能超过 300 个字符")
	public String getStations() {
		return stations;
	}

	public void setStations(String stations) {
		this.stations = stations;
	}

	@Length(min = 0, max = 20, message = "职务长度不能超过 20 个字符")
	public String getDutyCode() {
		return dutyCode;
	}

	public void setDutyCode(String dutyCode) {
		this.dutyCode = dutyCode;
	}

	@Length(min = 0, max = 50, message = "职务级别长度不能超过 50 个字符")
	public String getDutyLevel() {
		return dutyLevel;
	}

	public void setDutyLevel(String dutyLevel) {
		this.dutyLevel = dutyLevel;
	}

	@Length(min = 0, max = 20, message = "职称长度不能超过 20 个字符")
	public String getPostTitle() {
		return postTitle;
	}

	public void setPostTitle(String postTitle) {
		this.postTitle = postTitle;
	}

	@Length(min = 0, max = 50, message = "职称级别长度不能超过 50 个字符")
	public String getPostTitleLevel() {
		return postTitleLevel;
	}

	public void setPostTitleLevel(String postTitleLevel) {
		this.postTitleLevel = postTitleLevel;
	}

	@Length(min = 0, max = 1, message = "是否外籍人士长度不能超过 1 个字符")
	public String getIsForeign() {
		return isForeign;
	}

	public void setIsForeign(String isForeign) {
		this.isForeign = isForeign;
	}

	@Length(min = 0, max = 20, message = "民族长度不能超过 20 个字符")
	public String getNation() {
		return nation;
	}

	public void setNation(String nation) {
		this.nation = nation;
	}

	@Length(min = 0, max = 20, message = "政治面貌长度不能超过 20 个字符")
	public String getPolityStatus() {
		return polityStatus;
	}

	public void setPolityStatus(String polityStatus) {
		this.polityStatus = polityStatus;
	}

	@Length(min = 0, max = 20, message = "婚姻状况长度不能超过 20 个字符")
	public String getMarriStatus() {
		return marriStatus;
	}

	public void setMarriStatus(String marriStatus) {
		this.marriStatus = marriStatus;
	}

	@Length(min = 0, max = 20, message = "健康状况长度不能超过 20 个字符")
	public String getHealthStatus() {
		return healthStatus;
	}

	public void setHealthStatus(String healthStatus) {
		this.healthStatus = healthStatus;
	}

	@Length(min = 0, max = 100, message = "籍贯长度不能超过 100 个字符")
	public String getNativeplace() {
		return nativeplace;
	}

	public void setNativeplace(String nativeplace) {
		this.nativeplace = nativeplace;
	}

	@Length(min = 0, max = 1, message = "户口性质长度不能超过 1 个字符")
	public String getResidence() {
		return residence;
	}

	public void setResidence(String residence) {
		this.residence = residence;
	}

	@Length(min = 0, max = 18, message = "身份证长度不能超过 18 个字符")
	public String getIdcard() {
		return idcard;
	}

	public void setIdcard(String idcard) {
		this.idcard = idcard;
	}

	public Long getHeight() {
		return height;
	}

	public void setHeight(Long height) {
		this.height = height;
	}

	public Long getWeight() {
		return weight;
	}

	public void setWeight(Long weight) {
		this.weight = weight;
	}

	@Length(min = 0, max = 50, message = "档案编号长度不能超过 50 个字符")
	public String getArchiveNo() {
		return archiveNo;
	}

	public void setArchiveNo(String archiveNo) {
		this.archiveNo = archiveNo;
	}

	@Length(min = 0, max = 50, message = "教育程度长度不能超过 50 个字符")
	public String getEducation() {
		return education;
	}

	public void setEducation(String education) {
		this.education = education;
	}

	@Length(min = 0, max = 50, message = "学位长度不能超过 50 个字符")
	public String getDegrees() {
		return degrees;
	}

	public void setDegrees(String degrees) {
		this.degrees = degrees;
	}

	@Length(min = 0, max = 100, message = "毕业学校长度不能超过 100 个字符")
	public String getSchool() {
		return school;
	}

	public void setSchool(String school) {
		this.school = school;
	}

	@Length(min = 0, max = 100, message = "专业学科长度不能超过 100 个字符")
	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getGraduationDate() {
		return graduationDate;
	}

	public void setGraduationDate(Date graduationDate) {
		this.graduationDate = graduationDate;
	}

	@Length(min = 0, max = 20, message = "语言/外语长度不能超过 20 个字符")
	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	@Length(min = 0, max = 20, message = "语言等级长度不能超过 20 个字符")
	public String getLanguageLevel() {
		return languageLevel;
	}

	public void setLanguageLevel(String languageLevel) {
		this.languageLevel = languageLevel;
	}

	@Length(min = 0, max = 200, message = "特长长度不能超过 200 个字符")
	public String getSpecialty() {
		return specialty;
	}

	public void setSpecialty(String specialty) {
		this.specialty = specialty;
	}

	@Length(min = 0, max = 200, message = "兴趣爱好长度不能超过 200 个字符")
	public String getInterest() {
		return interest;
	}

	public void setInterest(String interest) {
		this.interest = interest;
	}

	@Length(min = 0, max = 20, message = "移动电话长度不能超过 20 个字符")
	@ExcelField(title = "电话", align = 2, sort = 35)
	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	@Length(min = 0, max = 20, message = "办公室电话长度不能超过 20 个字符")
	public String getOfficePhone() {
		return officePhone;
	}

	public void setOfficePhone(String officePhone) {
		this.officePhone = officePhone;
	}

	@Length(min = 0, max = 20, message = "传真长度不能超过 20 个字符")
	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	@Length(min = 0, max = 100, message = "电子邮件长度不能超过 100 个字符")
	@ExcelField(title = "邮箱", align = 2, sort = 40)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Length(min = 0, max = 20, message = "QQ长度不能超过 20 个字符")
	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	@Length(min = 0, max = 100, message = "户籍长度不能超过 100 个字符")
	public String getPerResidence() {
		return perResidence;
	}

	public void setPerResidence(String perResidence) {
		this.perResidence = perResidence;
	}

	@Length(min = 0, max = 255, message = "住址长度不能超过 255 个字符")
	@ExcelField(title = "地址", align = 2, sort = 45)
	public String getAddr() {
		return addr;
	}

	public void setAddr(String addr) {
		this.addr = addr;
	}

	@Length(min = 0, max = 20, message = "家庭电话长度不能超过 20 个字符")
	public String getHomePhone() {
		return homePhone;
	}

	public void setHomePhone(String homePhone) {
		this.homePhone = homePhone;
	}

	@Length(min = 0, max = 20, message = "参加工作年月长度不能超过 20 个字符")
	public String getJoinWork() {
		return joinWork;
	}

	public void setJoinWork(String joinWork) {
		this.joinWork = joinWork;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getJoinCorp() {
		return joinCorp;
	}

	public void setJoinCorp(Date joinCorp) {
		this.joinCorp = joinCorp;
	}

	@Length(min = 0, max = 100, message = "银行长度不能超过 100 个字符")
	public String getPsnBank() {
		return psnBank;
	}

	public void setPsnBank(String psnBank) {
		this.psnBank = psnBank;
	}

	@Length(min = 0, max = 50, message = "银行账号长度不能超过 50 个字符")
	public String getPsnAccount() {
		return psnAccount;
	}

	public void setPsnAccount(String psnAccount) {
		this.psnAccount = psnAccount;
	}

	@Length(min = 0, max = 100, message = "费用银行长度不能超过 100 个字符")
	public String getFeeBank() {
		return feeBank;
	}

	public void setFeeBank(String feeBank) {
		this.feeBank = feeBank;
	}

	@Length(min = 0, max = 50, message = "费用银行账号长度不能超过 50 个字符")
	public String getFeeAccount() {
		return feeAccount;
	}

	public void setFeeAccount(String feeAccount) {
		this.feeAccount = feeAccount;
	}

	@Length(min = 0, max = 50, message = "社会保障号长度不能超过 50 个字符")
	public String getSsno() {
		return ssno;
	}

	public void setSsno(String ssno) {
		this.ssno = ssno;
	}

	@Length(min = 0, max = 50, message = "公积金账号长度不能超过 50 个字符")
	public String getAccumulationAccount() {
		return accumulationAccount;
	}

	public void setAccumulationAccount(String accumulationAccount) {
		this.accumulationAccount = accumulationAccount;
	}

	@Length(min = 0, max = 1000, message = "照片路径长度不能超过 1000 个字符")
	public String getPicturePath() {
		return picturePath;
	}

	public void setPicturePath(String picturePath) {
		this.picturePath = picturePath;
	}

	@Length(min = 0, max = 20, message = "劳务公司编码长度不能超过 20 个字符")
	public String getServCorpCode() {
		return servCorpCode;
	}

	public void setServCorpCode(String servCorpCode) {
		this.servCorpCode = servCorpCode;
	}

	@Length(min = 0, max = 100, message = "劳务公司名称长度不能超过 100 个字符")
	public String getServCorpName() {
		return servCorpName;
	}

	public void setServCorpName(String servCorpName) {
		this.servCorpName = servCorpName;
	}

	@Length(min = 0, max = 64, message = "合并账号长度不能超过 64 个字符")
	public String getMergeAccountid() {
		return mergeAccountid;
	}

	public void setMergeAccountid(String mergeAccountid) {
		this.mergeAccountid = mergeAccountid;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getLeaveDate() {
		return leaveDate;
	}

	public void setLeaveDate(Date leaveDate) {
		this.leaveDate = leaveDate;
	}

	public User getLoginInfo() {
		if (loginInfo == null) {
			loginInfo = new User();
		}
		return loginInfo;
	}

	public void setLoginInfo(User loginInfo) {
		this.loginInfo = loginInfo;
	}

	@ExcelField(title = "是否登录用户", align = 2, sort = 50, dictType = "yes_no")
	public String getIsLoginUser() {
		if (isLoginUser != null) {
			return isLoginUser;
		} else if (loginInfo != null && StringUtils.isNotBlank(loginInfo.getUserCode())) {
			return Global.YES;
		} else {
			return Global.NO;
		}
	}

	public void setIsLoginUser(String isLoginUser) {
		this.isLoginUser = isLoginUser;
	}

	public String getPostCode() {
		return postCode;
	}

	public void setPostCode(String postCode) {
		this.postCode = postCode;
	}

	@ExcelField(title = "岗位", align = 2, sort = 30, fieldType = PostListType.class)
	public List<Post> getPostList() {
		return postList;
	}

	public void setPostList(List<Post> postList) {
		this.postList = postList;
	}

	@JsonIgnore
	public List<String> getPostIdList() {
		List<String> postIdList = Lists.newArrayList();
		for (Post post : postList) {
			postIdList.add(post.getId());
		}
		return postIdList;
	}

	public void setPostIdList(List<String> postIdList) {
		postList = Lists.newArrayList();
		if (postIdList != null) {
			for (String postId : postIdList) {
				Post post = new Post();
				post.setId(postId);
				postList.add(post);
			}
		}
	}

	
	

	public String getCompanyCode() {
		return company != null ? company.getCompanyCode() : null;
	}

	public void setCompanyCode(String companyCode) {
		if (company == null) {
			company = new Company();
		}
		company.setCompanyCode(companyCode);
	}

	public String getCompanyName() {
		return company != null ? company.getCompanyName() : null;
	}

	public void setCompanyName(String companyName) {
		if (company == null) {
			company = new Company();
		}
		company.setCompanyName(companyName);
	}

	public String getCompanyNameSimple() {
		return company != null ? company.getCompanyNameSimple() : null;
	}

	public void setCompanyNameSimple(String companyNameSimple) {
		if (company == null) {
			company = new Company();
		}
		company.setCompanyNameSimple(companyNameSimple);
	}

	// ============ 获取用户信息用来导出  excel==========
	
	@ExcelField(title = "拥有角色", align = 2, type = 2, sort = 55, fieldType = RoleListType.class)
	public List<Role> getLoginInfoRoleList() {
		return loginInfo != null ? loginInfo.getRoleList() : null;
	}

	public void setLoginInfoRoleList(List<Role> roleList) {
		if (loginInfo == null) {
			loginInfo = new User();
		}
		loginInfo.setRoleList(roleList);
	}

	//用户账号
	@ExcelField(title = "用户账号", align = 2, type = 2, sort = 60)
	public String getLoginInfoUserCode() {
		return loginInfo != null ? loginInfo.getUserCode() : null;
	}

	public void setLoginInfoUserCode(String userCode) {
		if (loginInfo == null) {
			loginInfo = new User();
		}
		loginInfo.setUserCode(userCode);
	}

	@ExcelField(title = "用户名称", align = 2, type = 2, sort = 65)
	public String getLoginInfoUserName() {
		return loginInfo != null ? loginInfo.getUserName() : null;
	}

	public void setLoginInfoUserName(String userName) {
		if (loginInfo == null) {
			loginInfo = new User();
		}
		loginInfo.setUserName(userName);
	}

	@ExcelField(title = "手机", align = 2, type = 2, sort = 70)
	public String getLoginInfoMobile() {
		return loginInfo != null ? loginInfo.getMobile() : null;
	}

	public void setLoginInfoMobile(String mobile) {
		if (loginInfo == null) {
			loginInfo = new User();
		}
		loginInfo.setMobile(mobile);
	}

	@ExcelField(title = "电话", align = 2, type = 2, sort = 75)
	public String getLoginInfoPhone() {
		return loginInfo != null ? loginInfo.getPhone() : null;
	}

	public void setLoginInfoPhone(String phone) {
		if (loginInfo == null) {
			loginInfo = new User();
		}
		loginInfo.setPhone(phone);
	}

	@ExcelField(title = "邮箱", align = 2, type = 2, sort = 80)
	public String getLoginInfoEmail() {
		return loginInfo != null ? loginInfo.getEmail() : null;
	}

	public void setLoginInfoEmail(String email) {
		if (loginInfo == null) {
			loginInfo = new User();
		}
		loginInfo.setEmail(email);
	}
	
	/**
	 * 是否查询所有员工
	 * @return
	 */
	public boolean isAll() {
		return BooleanUtils.toBoolean(isAll);
	}

	public void setAll(boolean isAll) {
		this.isAll = isAll;
	}

	public void setIsAll(String isAll) {
		this.isAll = Global.TRUE.equals(isAll);
	}

	public String getUserCode() {
		return userCode;
	}

	public void setUserCode(String userCode) {
		this.userCode = userCode;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getOfficeCode() {
		return officeCode;
	}

	public void setOfficeCode(String officeCode) {
		this.officeCode = officeCode;
	}

	public String getOfficeName() {
		return officeName;
	}

	public void setOfficeName(String officeName) {
		this.officeName = officeName;
	}

	public String getOfficeCode2() {
		return officeCode2;
	}

	public void setOfficeCode2(String officeCode2) {
		this.officeCode2 = officeCode2;
	}

	public String getOfficeName2() {
		return officeName2;
	}

	public void setOfficeName2(String officeName2) {
		this.officeName2 = officeName2;
	}

	public String getMemberCode() {
		return memberCode;
	}

	public void setMemberCode(String memberCode) {
		this.memberCode = memberCode;
	}

	public String getMemberName() {
		return memberName;
	}

	public void setMemberName(String memberName) {
		this.memberName = memberName;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	/**
	 * 状态标记（0：正常）
	 */
	public static final String EMP_STATUS_NORMAL = STATUS_NORMAL;

	/**
	 * 状态标记（1：删除）
	 */
	public static final String EMP_STATUS_DELETE = STATUS_DELETE;

	/**
	 * 状态标记（2：离职）
	 */
	public static final String EMP_STATUS_LEAVE = STATUS_DISABLE;
	
	

}